<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>系统设置</title>
{{>/WEB-INF/pages/common/meta_base.part.html}}
{{>/WEB-INF/pages/common/refs_base.part.html}}
{{>/WEB-INF/pages/common/refs_modal.part.html}}
<style type="text/css">
span.error {
	background-position: 0px 3px;
}
</style>
</head>
<body>
	{{>/WEB-INF/pages/common/layout_header.part.html}}
	<!---内容开始---->
	<div class="container">
		<ul class="breadcrumb">
			<li><a href="{{ctx}}">首页</a></li>
			<li class="active">系统设置</li>
		</ul>
		<hr class="hr1" />
		<div class="hr-10"></div>
		<div class="hr-10"></div>
		<div class="hr-10"></div>
		<div class="container nr_bgc">
			<div class="bg-ga container">
				<!-- 左边导航栏 -->
				<div class="col-sm-2 left_tab">
					<ul style="margin: 0">
						<li class="leff_tab_choose">系统设置</li>
						<li id="menu-choose1"><a style="color: black;"
							href="{{ctx}}/mam/setting/index/1">应用类别</a></li>
						<li id="menu-choose2"><a style="color: black;"
							href="{{ctx}}/mam/setting/index/2">模块类别</a></li>
						<li id="menu-choose3" style="color: black;" class="menu-choose">
						<a href="{{ctx}}/system/authSetting/view"><p style="color: black;">登录认证</p></a></li>
					</ul>
				</div>
				<!-- 右边的表格 -->
				<div class=" pull-left col-sm-10 right_tab">
					<div class="hr-10"></div>
					<div class="hr-10"></div>
					<div class="container bor-tab bg-st-white">
						<div class="mar-st-a30">
							<div class="bor-bot pad-st-b2">
								<div class="row">
									<div class="col-sm-6 text-left tit4-st">客户端登录认证配置</div>
									<div class="col-sm-6 text-right"></div>
								</div>
								<div class="hr"></div>
							</div>
							<form id="dataForm" name="dataForm" method="post"
								class="form-horizontal" action="{{ctx}}/system/authSetting/save"
								enctype="multipart/form-data">
								<input class="form-control wid75" name="id" type="hidden" id="cid" value="" />
								<input class="form-control wid75" name="clientType" type="hidden"
									id="authType" value="c" />
								<div class="mar-st-a30">
									<table width="90%" border="0" align="center" cellpadding="0"
										cellspacing="0" class="tab-td-pa">
										<tr>
											<td width="100" align="left">登录认证方式：</td>
											<td class="bd_sr"><select name="authMethod"
												onchange="changeAuthMethod(this.value,'c')" id="authMethod_c"
												class="form-control wid75">
													<option value="d">系统默认</option>
													<option value="e">扩展接口认证</option>
											</select></td>
										</tr>
									</table>
									<div class="hr-10"></div>
									<div id="ex"></div>
								</div>
								<div class="hr-10"></div>
								<div class="text-center">
									<button type="submit" class="btn btn-primary">保存</button>
								</div>
							</form>
						</div>
						<div class="mar-st-a30">
							<div class="bor-bot pad-st-b2">
								<div class="row">
									<div class="col-sm-6 text-left tit4-st">管理后台登录认证配置</div>
									<div class="col-sm-6 text-right"></div>
								</div>
								<div class="hr"></div>
							</div>
							<form id="backDataForm" name="backDataForm" method="post"
								class="form-horizontal" action="{{ctx}}/system/authSetting/save"
								enctype="multipart/form-data">
								<input class="form-control wid75" name="id" type="hidden" id="bid" value="" />
								<input class="form-control wid75" name="clientType" type="hidden"
									id="authType" value="b" />
								<div class="mar-st-a30">
									<table width="90%" border="0" align="center" cellpadding="0"
										cellspacing="0" class="tab-td-pa">
										<tr>
											<td width="100" align="left">登录认证方式：</td>
											<td class="bd_sr"><select name="authMethod"
												onchange="changeAuthMethod(this.value,'b')" id="authMethod_b"
												class="form-control wid75">
													<option value="d">系统默认</option>
													<option value="e">扩展接口认证</option>
											</select></td>
										</tr>
									</table>
									<div class="hr-10"></div>
									<div id="backEx"></div>
								</div>
								<div class="hr-10"></div>
								<div class="text-center">
									<button type="submit" class="btn btn-primary">保存</button>
								</div>
							</form>
						</div>
						<div class="hr-20"></div>
					</div>

				</div>
			</div>
		</div>
	</div>
	{{>/WEB-INF/pages/common/layout_footer.part.html}}

	<div id="setting" style="display: none;">
		<table width="90%" border="0" align="center"
			cellpadding="10" cellspacing="10" class="tab-td-pa">
			<tr>
				<td width="100" align="right">协议类别：</td>
				<td width="39%" class="bd_sr"><select name="protocol"
					id="protocol" class="form-control wid75" required>
						<option value="">请选择</option>
						<option value="http">http</option>
				</select></td>
			</tr>
			<tr>
				<td width="100" align="right" for="focusedInput">域名：</td>
				<td width="39%" class="bd_sr"><input
					class="form-control wid75" name="domain" type="text" id="domain"
					value="" /></td>
				<td width="100" align="right" for="focusedInput">IP地址：</td>
				<td class="bd_sr"><input class="form-control wid75" id="ip"
					name="ip" type="text" value="" required /></td>
			</tr>
			<tr>
				<td width="100" align="right" for="focusedInput">端口：</td>
				<td width="39%" class="bd_sr"><input class="form-control wid75"
					name="port" type="text" id="port" value="" /></td>
				<td width="100" align="right" for="focusedInput">URI：</td>
				<td class="bd_sr"><input class="form-control wid75" id="uri"
					name="uri" value="" type="text" /></td>
			</tr>
		</table>
	</div>
</body>
</html>
<script type="text/javascript">
<!--
	//$("#protocol option[value='{{authSetting.protocol}}']").attr("selected",
	//		true);
	//$("#authMethod option[value='{{authSetting.authMethod}}']").attr(
	//		"selected", true);

	function changeAuthMethod(value,clientType) {
		var at;
		if(clientType == "c"){
			at = $("#ex");
		} else {
			at = $("#backEx")
		}
		if (value == "e") {
			var d = $("#setting").html();
			at.html(d);
		} else {
			at.html("");
		}
	}

	function save(data){
		$.ajax({
			type : "POST",
			url : "{{ctx}}/system/authSetting/save",
			data : data,
			headers : {
				Accept : "application/json; charset=utf-8"
			},
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			dataType : "text",
			success : function(text) {
				var ret = $
						.parseJSON(text);
				if (ret.result) {
					bootbox
							.alert("信息保存成功");
				} else {
					bootbox
							.alert(ret.message);
				}
			},
			error : function(xhr) {
				bootbox
						.alert(xhr.responseText);
			}
		});
	}

	$(document).ready(
		function() {
			//聚焦第一个输入框
			$("#authMethod_c").focus();
			
			loadData();

			$("#dataForm").submit(
				function(evt) {
					var form = $(this);
					if (form.valid() == false) {
						evt.preventDefault();
						return false;
					}

					var data = $("#dataForm").serialize();
					save(data);						
					evt.preventDefault();
					return false;
			});
			
			$("#backDataForm").submit(
					function(evt) {
						var form = $(this);
						if (form.valid() == false) {
							evt.preventDefault();
							return false;
						}

						var data = $("#backDataForm").serialize();
						save(data);						
						evt.preventDefault();
						return false;
				});
	});
	
	function showData(obj){
		var domain=$('#setting').find('#domain');
		var ip = $('#setting').find('#ip');
		var port = $('#setting').find('#port');
		var uri = $('#setting').find('#uri');
		var cid = $('#cid');
		var bid = $('#bid');
		var authMethod_c = $('#authMethod_c');
		var authMethod_b = $('#authMethod_b');

		if(obj.authMethod == "e"){
			$("#setting, #protocol, option[value='" + obj.protocol + "']").attr("selected", true);
			domain.attr('value', obj.domain);
			ip.attr('value', obj.ip);
			port.attr('value', obj.port);
			uri.attr('value', obj.uri);
		}
		
		if(obj.clientType == "c"){
			cid.attr('value', obj.id);
			//authMethod_c.attr('value', obj.authMethod);
			$("#authMethod_c option[value='" + obj.authMethod + "']").attr("selected", true);
			changeAuthMethod(obj.authMethod, obj.clientType);
		} else {
			bid.attr('value', obj.id);
			$("#authMethod_b option[value='" + obj.authMethod + "']").attr("selected", true);
			changeAuthMethod(obj.authMethod, obj.clientType);
		}
	}
	
	function loadData(){
		$.ajax({
			url : "{{ctx}}/system/authSetting/list",
			type : 'post',
			//data : data,
			dataType : "json",
			headers : {
				Accept : "application/json; charset=utf-8"
			},
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : function(result) {
				$.each(result.data, function(key, value){
					showData(value);
				});
			},
			error : function() {
				bootbox.alert("服务器繁忙，请稍后再试！");
			}
		});
	}
//-->
</script>

